package controller;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

@ApplicationScoped
@ManagedBean
public class LoginBean {
	private String user;
	private String password;
	private String error;
	
	public void setUser(String user){
		this.user = user;
	}
	
	public String getUser(){
		return user;
	}
	
	public void setPassword(String password){
		this.password = password;
	}
	
	public String getPassword(){
		return password;
	}
	
	public void setError(String error){
		this.error = error;
	}
	
	public String getError(){
		return error;
	}
	
	public String login(){
		
		if (user.equals("user") && password.equals("password")){
			FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("username", 1);
			return "main";
		}
		else{
			setError("User and password are invalid!");
			return "login";
		}
	}
	
}

